package top.laoshuzi.server.camera.controller

import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiResponse
import io.swagger.annotations.ApiResponses
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import top.laoshuzi.server.camera.bean.dto.CameraTargetDTO
import top.laoshuzi.server.camera.bean.dto.LightStateDTO
import top.laoshuzi.server.camera.service.CameraService
import top.laoshuzi.server.camera.service.LightService
import top.laoshuzi.server.common.bean.ResponseResult
import top.laoshuzi.server.common.bean.ResponseResultUtils

@Api(tags = ["相机相关"])
@RestController
@RequestMapping(value = ["/api"])
class CameraController {

    @Autowired
    private lateinit var lightService: LightService

    @Autowired
    private lateinit var cameraService: CameraService

    @ApiOperation(value = "灯状态设置")
    @ApiResponses(value = [ApiResponse(code = 200, message = "Successed")])
    @RequestMapping(value = ["/light/state/{id}"], method = [RequestMethod.PATCH])
    fun setLightState(
            @PathVariable id: String,
            @RequestBody lightStateDTO: LightStateDTO): ResponseResult<*> {

        lightService.setLightState(id, lightStateDTO)
        return ResponseResultUtils.successed()
    }

    @ApiOperation(value = "灯状态获取")
    @ApiResponses(value = [ApiResponse(code = 200, message = "Successed")])
    @RequestMapping(value = ["/light/state/{id}"], method = [RequestMethod.GET])
    fun getLightState(
            @PathVariable id: String): ResponseResult<*> {

        val lightState = lightService.getLightState(id)
        return ResponseResultUtils.successed(lightState)
    }

    @ApiOperation(value = "云台方向控制")
    @ApiResponses(value = [ApiResponse(code = 200, message = "Successed")])
    @RequestMapping(value = ["/camera/direction/{id}"], method = [RequestMethod.PUT])
    fun controlDirection(
            @PathVariable id: String,
            @RequestBody cameraTargetDTO: CameraTargetDTO): ResponseResult<*> {

        cameraService.controlDirection(id, cameraTargetDTO)
        return ResponseResultUtils.successed()
    }


}
